package com.dm.hdfxxt.warehousemanage.controller;

import com.dm.hdfxxt.warehousemanage.service.WhService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "goWh")
public class WhController {
    private static final Logger logger = LoggerFactory.getLogger(WhController.class);

    @Autowired
    private WhService whService;

    /**
     * @Description 保存仓库信息
     * @Author zhangxue
     * @Date 18:29 2018/9/29
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/saveWh",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> saveWh(@RequestBody Map<String,Object> param){
        Map<String,Object> ResultMap = new HashMap<>();
        ResultMap = whService.saveWh(param);
        return ResultMap;
    }

    /**
     * @Description 编辑仓库信息
     * @Author zhangxue
     * @Date 18:29 2018/9/29
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/editWh",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> editWh(@RequestBody Map<String,Object> param){
        Map<String,Object> ResultMap = new HashMap<>();
        ResultMap = whService.editWh(param);
        return ResultMap;
    }

    /**
     * @Description 删除仓库信息
     * @Author zhangxue
     * @Date 18:29 2018/9/29
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/delWh",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> delWh(@RequestBody Map<String,Object> param){
        Map<String,Object> ResultMap = new HashMap<>();
        ResultMap = whService.delWh(param);
        return ResultMap;
    }

    /**
         * @Description  查询所有仓库
         * @Author zhangxue
         * @Date 11:35 2018/10/30
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryAllWh",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllWh(@RequestBody Map<String,Object> param){
        Map<String,Object> ResultMap = new HashMap<>();
        List<Map<String,Object>> ResultList = whService.queryAllWh(param);
        ResultMap.put("ResultList",ResultList );
        return ResultMap;
    }

    @RequestMapping(value="/queryWhByParm",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryWhByParm(HttpServletRequest request,@RequestBody Map<String, Object> param){
        param.put("Store",request.getSession().getAttribute("Store"));
        Map<String,Object> ResultMap = new HashMap<>();
        List<Map<String,Object>> ResultList = whService.queryWhByParm(param);
        ResultMap.put("ResultList",ResultList );
        return ResultMap;
    }
}
